<%@ page import="java.util.Locale" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<html>
  <head>
      <title>处理日期</title>
      <style type="text/css">
        .wrapper {
          text-align: center ;
          border: 1px solid blue ;
          margin: 15px auto ;
        }
      </style>
  </head>
  <body>

    <%-- JSP标准动作 ( JSP Starand Actions ) --%>
    <jsp:useBean id="today" class="java.util.Date" scope="page"></jsp:useBean>
    <%--
      java.util.Date today = new java.util.Date();
      pageContext.setAttribute( "today" , today , PageContext.PAGE_SCOPE );
    --%>
    <div class="wrapper">${ today }</div>

    <div class="wrapper">
      <fmt:formatDate value="${ today }" type="date" ></fmt:formatDate>
    </div>

    <div class="wrapper">
      <fmt:formatDate value="${ today }" type="time" ></fmt:formatDate>
    </div>

    <div class="wrapper">
      <fmt:formatDate value="${ today }" type="both" ></fmt:formatDate>
    </div>

    <div class="wrapper">
      <fmt:formatDate value="${ today }" type="both" dateStyle="short" timeStyle="short"></fmt:formatDate>
    </div>

    <div class="wrapper">
      <fmt:formatDate value="${ today }" type="both" dateStyle="long" timeStyle="long"></fmt:formatDate>
    </div>

    <div class="wrapper">
      <fmt:formatDate value="${ today }" type="both" dateStyle="full" timeStyle="full"></fmt:formatDate>
    </div>

    <div class="wrapper">
      <fmt:formatDate value="${ today }" pattern="G yyyy年MM月dd日 EEEE HH:mm:ss.SSS"></fmt:formatDate>
    </div>

    <hr>

    <c:set var="str" value="2021/12/28" scope="page"></c:set>

    <fmt:parseDate pattern="yyyy/MM/dd" value="${ str }" var="date" scope="page"></fmt:parseDate>
    <div class="wrapper">
      ${ date }
    </div>

    <div class="wrapper">
      <fmt:parseDate pattern="yyyy/MM/dd" value="${ str }" ></fmt:parseDate>
    </div>

    <hr>

    <%-- 遍历 Locale 数组并取得其中的每一个 Locale 实例 --%>
    <c:forEach items="<%= Locale.getAvailableLocales() %>" var="locale">
      <%-- 将本次遍历得到的 Locale 实例设置为当前的 Locale --%>
      <fmt:setLocale value="${ locale }" />
      <%-- 根据不同的 Locale 完成数字格式化操作 --%>
      <div class="wrapper">
        <span> ${ locale.displayCountry } </span>
        <span> <fmt:formatDate value="${ today }" /> </span>
      </div>
    </c:forEach>

  </body>
</html>
